home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3551 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  885 b 

  1. Path: newshub.cts.com!usenet
  2. From: jfitz@vmbb.cts.com (Jim Fitzgerald)
  3. Newsgroups: comp.lang.c
  4. Subject: Type conversion
  5. Date: Mon, 29 Jan 1996 23:01:38 GMT
  6. Organization: CTS Network Services
  7. Message-ID: <4ejjka$2rf@news3.cts.com>
  8. NNTP-Posting-Host: neutrino.cts.com
  9.  
  10.  
  11. Hi,
  12.  
  13.   Was wondering if a guru out there could tell me why the following
  14. code fragment for extracting an long from a buffer does not work.
  15. Following the bad code, is a fragment that does work.. but is fairly
  16. cheezy! )..
  17.  
  18. This code compiles and runs but returns INCORRECT results:
  19.  
  20. char buffer[512];
  21. long  node_left, node_right;
  22. {
  23.   node_left  =  (long)*(buffer+4);
  24.   node_right=  (long)*(buffer+8);
  25. }
  26.  
  27. This code runs and returns CORRECT results:
  28.  
  29. char buffer[512];
  30. long node_left, node_right;
  31. long *bogus;
  32. {
  33.   bogus = buffer+4;
  34.   node_left = *bogus;
  35.   bogus = buffer+8;       
  36.   node_right= *bogus;
  37. }
  38.  
  39. Thanks!
  40. -Jim
  41.  
  42.  
  43.